home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 May / macformat-050.iso / Shareware Plus / Developers / Find_icon folder / Headers / cheap-exceptions.h next >
Encoding:
C/C++ Source or Header  |  1997-01-12  |  1.7 KB  |  69 lines  |  [TEXT/CWIE]

  1. /*
  2.     These exception handling macros are based on the article "Living
  3.     in an Exceptional World", by Sean Parent, in _develop_ issue
  4.     11, August 1992.  He used "nrequire" where I use "forbid".
  5.     
  6.     Normally, each require or forbid macro needs to have a unique
  7.     exception-handling label, because of the use of resumeLabel.
  8.     However one could give resumeLabel a null definition and then have
  9.     multiple exceptions sharing handler labels.
  10. */
  11.  
  12. #if        DEBUGGING
  13.     #define        DEBUGSTR( x )    DebugStr( "\p" x )
  14.     #define        DEBUGMSG( x )    DebugStr( "\p" # x )
  15. #else
  16.     #define        DEBUGSTR( x )
  17.     #define        DEBUGMSG( x )
  18. #endif
  19.  
  20.  
  21. #ifndef resumeLabel
  22.     #define        resumeLabel(exception)    resume_ ## exception:
  23. #endif
  24.  
  25. #define        require(assertion, exception)            \
  26.                 do {                                \
  27.                     if (assertion) ;                \
  28.                     else                            \
  29.                     {                                \
  30.                         DEBUGMSG( exception );        \
  31.                         goto exception;                \
  32.                         resumeLabel(exception);        \
  33.                     }                                \
  34.                 } while (false)
  35.  
  36. #define        require_action(assertion, exception, action)        \
  37.                 do {                                \
  38.                     if (assertion) ;                \
  39.                     else                            \
  40.                     {                                \
  41.                         action;                        \
  42.                         DEBUGMSG( exception );        \
  43.                         goto exception;                \
  44.                         resumeLabel(exception);        \
  45.                     }                                \
  46.                 } while (false)
  47.  
  48. #define        forbid(bad_assertion, exception)        \
  49.                 do {                                \
  50.                     if (bad_assertion)                \
  51.                     {                                \
  52.                         DEBUGMSG( exception );        \
  53.                         goto exception;                \
  54.                         resumeLabel(exception);        \
  55.                     }                                \
  56.                 } while (false)
  57.  
  58. #define        forbid_action(bad_assertion, exception, action)        \
  59.                 do {                                \
  60.                     if (bad_assertion)                \
  61.                     {                                \
  62.                         action;                        \
  63.                         DEBUGMSG( exception );        \
  64.                         goto exception;                \
  65.                         resumeLabel(exception);        \
  66.                     }                                \
  67.                 } while (false)
  68.  
  69.